package com.czh.practice.api.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class ResponseResult<T> implements Serializable {

    private Integer code;

    private String message;

    private Boolean success;

    private T data;

    ResponseResult(){
        this.success = true;
        this.code = ResultCodeEnum.SUCCESS.getCode();
        this.message = ResultCodeEnum.SUCCESS.getDesc();
    }

    public static <T> ResponseResult<T> ok(){
        return new ResponseResult<>();
    }

    public static <T> ResponseResult<T> ok(T data){
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setData(data);
        return responseResult;
    }

    public static <T> ResponseResult<T> fail(String message){
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setSuccess(false);
        responseResult.setCode(ResultCodeEnum.FAIL.getCode());
        responseResult.setMessage(message);
        return responseResult;
    }
    public static<T> ResponseResult<T> fail(){
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setSuccess(false);
        responseResult.setCode(ResultCodeEnum.FAIL.getCode());
        responseResult.setMessage(ResultCodeEnum.FAIL.getDesc());
        return responseResult;
    }

    public static<T> ResponseResult<T> fail(T data){
        ResponseResult<T> responseResult = new ResponseResult<>();
        responseResult.setSuccess(false);
        responseResult.setCode(ResultCodeEnum.FAIL.getCode());
        responseResult.setMessage(ResultCodeEnum.FAIL.getDesc());
        responseResult.setData(data);
        return responseResult;
    }

}
